//
//  BBSAddCaseCell.m
//  QuickCure
//
//  Created by 石玄机 on 16/9/14.
//  Copyright © 2016年 haoge. All rights reserved.
//

#import "BBSAddCaseCell.h"

@interface BBSAddCaseCell ()

//时间
@property (weak, nonatomic) UILabel *timeLabel;

//图片
@property (weak, nonatomic) UIImageView *picture;

//疾病类型标题
@property (weak, nonatomic) UILabel *diseaseTypeTitleLabel;

//基本类型标题
@property (weak, nonatomic) UILabel *diseaseSubdivideTitleLabel;

//疾病类型具体
@property (weak, nonatomic) UILabel *diseaseType;

//基本类型具体
@property (weak, nonatomic) UILabel *disezseSubdivide;


//疾病描述
@property (weak, nonatomic)  UILabel *textViewTextLabel;



@end

@implementation BBSAddCaseCell



-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{

    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setupUI];
    }

    return self;
}

/**
 创建疾病标题
 */
- (UILabel *)addTitleLabelWithString:(NSString *)str top:(UIView *)topView{
    UILabel *label = [[UILabel alloc] init];
    
    label.text = str;
    
    [self.contentView addSubview:label];
    
    [label makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.picture.right).offset(10);
        make.top.equalTo(topView.mas_bottom).offset(10);
    }];
    
    return label;
}


/**
 创建疾病详情
 */
- (UILabel *)addLabelWithString:(NSString *)str top:(UIView *)topView{
    
    UILabel *label = [[UILabel alloc] init];
    label.textColor = [UIColor lightGrayColor];
    label.font = FONT(16);
    
    label.text = str;
    
    [self.contentView addSubview:label];
    
    [label makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.diseaseTypeTitleLabel.right).offset(15);
        make.top.equalTo(topView.mas_bottom).offset(10);
    }];
    
    return label;
}



-(void)setupUI{

    UILabel *timeLabel = [[UILabel alloc] init];
    self.timeLabel = timeLabel;
    timeLabel.text = @"rersfdf";
    [self.contentView addSubview:timeLabel];
    timeLabel.font = FONT(14);
    timeLabel.textColor = [UIColor lightGrayColor];
    
    [timeLabel makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView);
        make.left.equalTo(self.contentView).offset(40);
    }];
    
    UIImageView *picture = [[UIImageView alloc] init];
    self.picture = picture;
//    picture.image = [UIImage imageNamed:@"qqIcon"];
    [self.contentView addSubview:picture];
    
    [picture makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(timeLabel.bottom).offset(5);
        make.left.equalTo(timeLabel);
        make.size.equalTo(CGSizeMake(100,  100));
    }];
    
    UILabel *diseaseTypeTitleLabel = [self addTitleLabelWithString:@"疾病类型:" top:timeLabel];
    diseaseTypeTitleLabel.font = kFONT14;
    self.diseaseTypeTitleLabel = diseaseTypeTitleLabel;
    
    UILabel *diseaseSubdivideTitleLabel = [self addTitleLabelWithString:@"基本类型:" top:diseaseTypeTitleLabel];
    diseaseSubdivideTitleLabel.font = kFONT14;
    self.diseaseSubdivideTitleLabel = diseaseSubdivideTitleLabel;
    
    UILabel *diseaseType = [self addLabelWithString:@"神经" top:timeLabel];
    self.diseaseType = diseaseType;
    diseaseType.font = kFONT14;
    
    UILabel *disezseSubdivide = [self addLabelWithString:@"神经病" top:diseaseTypeTitleLabel];
    self.disezseSubdivide = disezseSubdivide;
    disezseSubdivide.font = kFONT14;
    
    UILabel *textViewTextLabel = [self addTitleLabelWithString:@"暂没有病症描述" top:diseaseSubdivideTitleLabel];
    textViewTextLabel.font = FONT(13);
    self.textViewTextLabel = textViewTextLabel;
    textViewTextLabel.textColor = [UIColor lightGrayColor];
    
    UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"illness_rb_img_sel.png"]];
    [self.contentView addSubview:imageView];
    
    [imageView makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView);
        make.left.equalTo(self.contentView).offset(10);
        make.width.height.equalTo(15);
    }];
    
    UIImageView *lineImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"nav"]];
    [self.contentView addSubview:lineImage];
    
    [lineImage makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(1);
        make.centerX.equalTo(imageView);
        make.top.equalTo(imageView.bottom);
        make.bottom.equalTo(self.contentView);
    }];
}



- (void)setModel:(BBSAddCaseModel *)model{
    
    _model = model;
    
    self.timeLabel.text = model.addTime;
    
    self.diseaseType.text = model.diseaseType;
    
    self.disezseSubdivide.text = model.subdivideType;
    
    if (model.textViewText.length != 0) {
        
        self.textViewTextLabel.text = model.textViewText;
    }else{
        self.textViewTextLabel.text = @"暂没有病症描述";
    }

    
    if (model.imageData.length ==0) {
    
        [self.diseaseTypeTitleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
            
            make.top.equalTo(self.timeLabel.mas_bottom).offset(10);
            make.left.equalTo(self.timeLabel);
        }];
        
        [self.diseaseSubdivideTitleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
            
            make.top.equalTo(self.diseaseTypeTitleLabel.mas_bottom).offset(10);
            
            make.left.equalTo(self.diseaseTypeTitleLabel);
            
        }];
        
        [self.textViewTextLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
            
            make.top.equalTo(self.diseaseSubdivideTitleLabel.mas_bottom).offset(10);
            make.left.equalTo(self.diseaseSubdivideTitleLabel);
            
        }];
        
    }
    
    if(model.imageData.length != 0){
        
        self.picture.image = [UIImage imageWithData:model.imageData];
        
        [self.diseaseTypeTitleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
            
            make.left.equalTo(self.picture.right).offset(10);
            make.top.equalTo(self.timeLabel.mas_bottom).offset(10);
        }];
        
        [self.diseaseSubdivideTitleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
            
            make.left.equalTo(self.picture.right).offset(10);
            make.top.equalTo(self.diseaseTypeTitleLabel.mas_bottom).offset(10);
            
        }];
        
        [self.textViewTextLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
            
            make.top.equalTo(self.diseaseSubdivideTitleLabel.mas_bottom).offset(10);
            make.left.equalTo(self.diseaseSubdivideTitleLabel);
            
        }];


    }
}





@end
